import Vue from 'vue'
import axios from 'axios'
import elementUi from 'element-ui';
axios.interceptors.request.use((config) => {
	let token = Vue.local.get('token');
	config.headers['Authorization'] = token;
	config.baseURL = Vue.prototype.baseURL;
	return config
})

axios.interceptors.response.use((response) => {
	let res = response.data;
	// console.log(res);
	if (res.code != 0 && res.code != 7) {
		if (res.msg == "用户身份验证失败" || res.msg == "您已经被强制下线,请重新登陆" || res.msg == "令牌失效") {
			Vue.local.clear();
			location.href = '/#/login';
		}
		if (res.msg) {
			elementUi.Message({
				message: res.msg,
				type: "warning"
			})
		}
	}
	return response
}, err => {
	return Promise.reject(err)
})

export default axios